﻿#include "pch.h"
#include "Camera.h"

#include "glm/gtc/matrix_transform.hpp"

namespace Engine
{
	Camera::Camera(const float left, const float right, const float bottom, const float top)
		: viewMatrix(1.0f), projectionMatrix(glm::ortho(left, right, bottom, top, -1.0f, 1.0f))
	{
	}

	void Camera::SetProjectionMatrix(const float left, const float right, const float bottom, const float top)
	{
		projectionMatrix = glm::ortho(left, right, bottom, top, -1.0f, 1.0f);
		viewProjectionMatrix = projectionMatrix * viewMatrix;
	}

	void Camera::SetPosition(const glm::vec3& position)
	{
		this->position = position;
		UpdateViewMatrix();
	}

	void Camera::SetRotation(const float& rotation)
	{
		this->rotation = rotation;
		UpdateViewMatrix();
	}

	void Camera::UpdateViewMatrix()
	{
		const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) *
			glm::rotate(glm::mat4(1.0f), glm::radians(rotation), glm::vec3(0.0f, 0.0f, 1.0f));

		viewMatrix = glm::inverse(transform);
		viewProjectionMatrix = projectionMatrix * viewMatrix;
	}
}
